package com.application.Activity;

import com.application.Activity.adapterListActivity.MyExpandableListAdapter;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseExpandableListAdapter;
import android.widget.ExpandableListAdapter;
import android.widget.ExpandableListView;
import android.widget.LinearLayout;
import android.widget.TextView;


public class expandActivity extends Activity {
	
	ExpandableListAdapter mAdapter;
	LayoutInflater inflator=null;
	
	 @Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.layout_comment_tree);
	        inflator = LayoutInflater.from(this.getApplicationContext());
	        ExpandableListView lv=(ExpandableListView)findViewById(R.id.expandListComment);
	      //  mAdapter=new expandListAdapter(this);
	       
	        String[] groups = { "People Names"};//, "Dog Names", "Cat Names", "Fish Names" };
	        String[][] children = {
	                { "Arnold", "Barry", "Chuck", "David" }//,
//	                { "Ace", "Bandit", "Cha-Cha", "Deuce" },
//	                { "Fluffy", "Snuggles" },
//	                { "Goldy", "Bubbles" }
	        };
	        mAdapter=new MyExpandableListAdapter(groups,children);
	        lv.setAdapter(mAdapter);
	    }
	 
	 //=================================================================================================
	 public class MyExpandableListAdapter extends BaseExpandableListAdapter {
	        // Sample data set.  children[i] contains the children (String[]) for groups[i].
	       // public  String[] groups1 =null; { "People Names", "Dog Names", "Cat Names", "Fish Names" };
	     //   public  String[][] children1 = null;{
//	                { "Arnold", "Barry", "Chuck", "David" },
//	                { "Ace", "Bandit", "Cha-Cha", "Deuce" },
//	                { "Fluffy", "Snuggles" },
//	                { "Goldy", "Bubbles" }
//	        };
	        private String[] groups=null;
	        private String[][] children=null;
	        public MyExpandableListAdapter(String[] groups1,String[][] children1){
	        	groups=groups1;
	        	
	        	children=children1;
	        }
	        public Object getChild(int groupPosition, int childPosition) {
	            return children[groupPosition][childPosition];
	        }

	        public long getChildId(int groupPosition, int childPosition) {
	            return childPosition;
	        }

	        public int getChildrenCount(int groupPosition) {
	            return children[groupPosition].length;
	        }

	        public TextView getGenericView() {
	            // Layout parameters for the ExpandableListView
	            AbsListView.LayoutParams lp = new AbsListView.LayoutParams(
	                    ViewGroup.LayoutParams.MATCH_PARENT, 64);

	            TextView textView = new TextView(getApplicationContext());
	            textView.setLayoutParams(lp);
	            // Center the text vertically
	            textView.setGravity(Gravity.CENTER_VERTICAL | Gravity.LEFT);
	            // Set the text starting position
	            textView.setPadding(36, 0, 0, 0);
	            return textView;
	        }

	        public View getChildView(int groupPosition, int childPosition, boolean isLastChild,
	                View convertView, ViewGroup parent) {
	        	View myView=convertView;
	        	if(myView==null)
	    		{
	        		myView=inflator.inflate(R.layout.row_comment,null);
	    		}
	        	
//	        	TextView txt1=(TextView)myView.findViewById(R.id.txtTitle);
//	        	txt1.setText(getChild(groupPosition, childPosition).toString());
//	        	txt1.setGravity(Gravity.CENTER_VERTICAL);
	        	//===============
	        	
        	 ExpandableListView lvChild=(ExpandableListView)myView.findViewById(R.id.expandListViewChild);
        	 
	        	FillChildren(lvChild);
	        	
	        	//=========================
//	            TextView textView = getGenericView();
//	            textView.setText(getChild(groupPosition, childPosition).toString());
//	            return textView;
	        	return myView;
	        }

	        public Object getGroup(int groupPosition) {
	            return groups[groupPosition];
	        }

	        public int getGroupCount() {
	            return groups.length;
	        }

	        public long getGroupId(int groupPosition) {
	            return groupPosition;
	        }

	        public View getGroupView(int groupPosition, boolean isExpanded, View convertView,
	                ViewGroup parent) {
	        	View v=convertView;
	        	if(v==null){
	        		v=inflator.inflate(R.layout.row_comment,null);
	        	}
//	        	TextView tv=(TextView)v.findViewById(R.id.txtContent);
//	        	tv.setText(getGroup(groupPosition).toString());
	        	TextView tv1=(TextView)v.findViewById(R.id.txtTitle);
	        	tv1.setText(getGroup(groupPosition).toString());
	        	//================

		        //=====================		        	
		        	
//	            TextView textView = getGenericView();
//	            textView.setText(getGroup(groupPosition).toString());
//	            return textView;
	        	return v;
	        }

	        public boolean isChildSelectable(int groupPosition, int childPosition) {
	            return true;
	        }

	        public boolean hasStableIds() {
	            return true;
	        }

	    }
	 
	 public void FillChildren(ExpandableListView lv){
		 String[] group = { "People", "Dog", "Cat", "Fish" };
	        String[][] child = {
//	                { "Arnold", "Barry"},
//	                { "Ace", "Bandit" },
//	                { "Fluffy", "Snuggles" },
//	                { "Goldy" }
	        };
		 MyExpandableListAdapter adapterChild=new MyExpandableListAdapter(group,child);
	        lv.setAdapter(adapterChild);
	 }
}
